package com.wwl.deliveryappointmentbackend.configure;

import com.wwl.deliveryappointmentbackend.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;
import java.nio.file.Paths;

@Configuration
public class FileUploadConfig implements WebMvcConfigurer {
    @Value("${Constant.upload.imgPath}")
    private String path;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 将自定义的拦截器添加到拦截器链中，并指定拦截的路径
        registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/sys/**"); // 拦截后台请求路径
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String staticMapping = "/images/**";
        String localDirectory = "file:"+ Paths.get(path) + File.separator;
        registry.addResourceHandler(staticMapping).addResourceLocations(localDirectory);
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
